// ==UserScript==
// @name         江苏教师培训
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       xuan
// @match        https://www.jste.net.cn/lfv5/learnContentLib/studentMain.action
// @icon
// @grant        none
// ==/UserScript==

var started = false;

function jumpNext(){
    this.minRecordSeconds = 60; //最少记录的学习时间 秒,必须为60的倍数，否则会有误差
    //console.log('minRecordSeconds',this.minRecordSeconds)
    this.refreshRecordSeconds = 60; //重复调用的时间，在客户端缓存时间，累计超过minRecordSeconds则保存，需要可以整除minRecordSeconds
    if(!started){
      this.startCountDown(0);
      started = true;
    }else{
      // window.setTimeout(this.continueRecord(), 10000);
      // window.setTimeout($.get("count.jsp?mid=" + this.mjson.materialId), 10000);
    }
    //console.log('this.curFileItem',this.curFileItem)
    var needList= this.mjson.itemList.filter(e => { return e.folder==0 && e.isFolder==0 && e.maxLearnTime>0&&e.enableLearnTime==1}).filter(e=>{return e.itemTitle.indexOf("mp4")>-1}).sort((a,b)=>{return a.parentItemId.localeCompare(b.parentItemId)})
    var currtId = needList.findIndex(e =>  { return e==this.curFileItem})
    console.log("索引",currtId,"标题：",this.curFileItem['itemTitle'],"已经学习：",this.learnTime[this.curFileItem['itemId']],"需要学习：",this.curFileItem['minLearnTime'])
    if(this.checkItemFinished(this.curFileItem)){
        console.log('当前课程达到学习目标！')
        console.log("需要跳转：",currtId+1)
        window.open('https://www.jste.net.cn/lfv5/learnContentLib/studentMain.action#item/'+needList[currtId+1]['itemId'],'_self');
    }
    setTimeout(jumpNext, 10000);
};

(function() {
    //'use strict';
    setTimeout(jumpNext, 3000)

    // Your code here...
})();